<?php
namespace app\home\controller;
use \think\Db;


class Contact extends \think\Controller
{
    public function index(){
        $category = Db::table('baode_article_category')->where('title','联系我们')->find();
        $categoryArr = Db::table('baode_article_category')->where('pid',intval($category['id']))->select();
        input('category_id') and $category_id = input('category_id') or $category_id = $categoryArr[0]['id'];
        $contactArr = Db::table('baode_article')->where('category_id',intval($category_id))->find();
        //var_dump($contactArr);die;
        return $this->allFetch(get_defined_vars());
    }
    
    public function message(){
        if(input('sbt')){
            (!input('username') ||  !input('tel') ||  !input('mark')) and echojson("fail", '2');
            $data['names'] = input('username');
            $data['telephone'] = input('tel');
            $data['content'] = htmlspecialchars(input('mark'));
            $data['type'] = 1;
            $data['on_time'] = time();
            Db::table('baode_message')->insert($data);
            echojson('ok', '1');
        }
        $category = Db::table('baode_article_category')->where('title','联系我们')->find();
        $categoryArr = Db::table('baode_article_category')->where('pid',intval($category['id']))->select();
        input('category_id') and $category_id = input('category_id') or $category_id = $categoryArr[0]['id']; 
        return $this->allFetch(get_defined_vars());
    }
}
